<title>数据审核</title>
<div class="layui-card layadmin-header">
	<div class="layui-breadcrumb" lay-filter="breadcrumb" lay-separator=">">
        <a lay-href=""><i class="layui-icon layui-icon-locate"></i>您当前的位置：</a>
		<a><cite class="first-breadcrumb">审核管理</cite></a>
        <a><cite class="second-breadcrumb">数据审核</cite></a>
        <a><cite class="third-breadcrumb"></cite></a>
	</div>
</div>

<style>
    .top-part{
        margin: 12px 0 20px 0;
    }
    .left-card, .right-card, .layui-card{
        border-radius: 4px;
    }
    .right-card{
        height: 425px;
        background: #fff;
    }
    .scroll{
        overflow-y: scroll;
    }
    .task-ul{
        height: 345px;
        padding: 18px 0;
    }
    .task-ul ul{
        height: 100%;
        font-size: 14px;
    }
    .task-ul ul li{
        height: 32px;
        line-height: 32px;
        padding: 0 25px 0 20px;
        cursor: default;
    }
    .task-ul ul li+li:hover{
        background: #DCE7F4;
    }
    .layui-table td, .layui-table th{
        text-align: center;
    }
    .layui-table td[data-field="6"]{
        text-align: left;
    }
    .filling{
        display: inline-block;
        width: 72px;
        height: 18px;
        line-height: 20px;
        font-size: 12px;
        background-color: #53C553;
        border-radius: 9px;
        color: #FEFFFE;
    }
    .addLine, .delLine, .checkLine{
        position: relative;
        width: 24px;
        height: 22px;
        border: none;
        background-position: center center;
        background-repeat: no-repeat;
        margin-top: 4px;
        cursor: pointer;
    }
    .addLine{
        background: url(../../../../dist/style/res/formFill/add.png);
        margin-right: 40px;
    }
    .delLine{
        background: url(../../../../dist/style/res/formFill/del.png);
    }
    .checkLine{
        background-color: transparent;
        border: 1px solid #FF4E32;
        border-radius: 2px;
    }
    .checkLine .layui-icon{
        position: absolute;
        top: -1px;
        left: 2px;
        font-size: 19px;
        color: #FF4E32 !important;
		border-color: #FF4E32;
    }
    /* 样式调整 */
    .left-card{
        margin-bottom: 0;
    }
    .layui-card-header{
        height: 19px;
        line-height: normal;
        padding: 10px;
        background-color: #F6F7F8;
    }
    .layui-card-body{
        padding: 0;
    }
    .card-header-icon{
        width: 18px;
        height: 18px;
    }
    .card-header-title{
        margin-left: 10px;
    }
    .layui-table-view .layui-table th, .layui-table-view .layui-table td{
        padding: 4px 0;
    }
    .download-file{
        color: #23559D;
        cursor: pointer;
    }
    .download-file:hover{
        color: #13ADFD;
    }
    .btn-submit, .btn-forward, .btn-assign, .btn-return{
        height: 22px;
        font-size: 12px;
        border-radius: 4px;
    }
    .btn-submit{
        width: 48px;
        border: 1px solid #4BAA0B;
        color: #4BAA0B;
    }
    .btn-forward{
        width: 48px;
        border: 1px solid #1C74D4;
        color: #1C74D4;
    }
    .btn-assign{
        width: 60px;
        border: 1px solid #0078FF;
        color: #0078FF;
    }
    .btn-return{
        width: 62px;
        border: 1px solid #828282;
        color: #828282;
    }
    .layui-btn+.layui-btn{
        margin-left: 0;
    }
    .layui-fluid{
        padding: 0 15px 0 15px;
    }

    /* 待办任务样式 */
    .undo-task{
        padding-left: 10px;
    }
    .task-content-box{
        float: left;
        width: 70%;
        height: 32px;
        text-overflow: ellipsis;
        overflow: hidden;
    }
    .task-num{
        display: inline-block;
        width: 25px;
        font-size: 16px;
        color: #373737;
        font-weight:bold;
    }
    .task-content{
        color: #373737;
    }
    .task-time{
        float: right;
        width: 30%;
        height: 32px;
        color:#666666;
        overflow: hidden;
        text-align: right;
    }

    .select-form-header{
        position: relative;
    }
    .card-header-right{
        position: absolute;
        right: 0;
        top: 5px;
    }
    .layui-card .layui-tab{
        margin-top: 13px;
        z-index: 9999;
    }
    .layui-tab-card>.layui-tab-title{
        background: #fff;
    }
    .layui-tab-card{
        border-top: none;
    }
    .select-form-box{
        min-height: 400px;
    }
    .layui-tab-content{
        padding: 15px 9px;
    }
    .layui-table tbody tr.bgRed{
        background: red;
    }
    .task-btn-group{
        margin-bottom: 5px;
    }
    .layui-btn-refresh, .layui-btn-pass, .layui-btn-back{
        width: 71px;
        height: 30px;
        line-height: 30px;
        background-color: #2669B1;
        padding-left: 31px;
        font-size: 14px;
        color: #FFFFFF;
        background: url(../../../../dist/style/res/about/refresh.png) no-repeat #2669B1; 
        background-position: 9px 8px;
    }
    .layui-btn-pass{
        background: url(../../../../dist/style/res/about/save.png) no-repeat #47CD07;
        background-position: 10px 6px;
        margin-right: 12px;
    }
    .layui-btn-back{
        background: url(../../../../dist/style/res/about/return.png) no-repeat #F3BD05;
        background-position: 9px 4px;
    }
    .layui-table-cell{
        height: inherit;
        line-height: 27px;
        text-align: center;
    }
    .layui-table-view .layui-table{
        width:100%;
    }
    .layui-badge{
        height: 19px;
        line-height: 21px;
        border-radius: 9px;
        padding: 0 16px;
    }
    .layui-table-box .layui-table[lay-even] tbody tr.lineactive{
        background-color: #FDE7A3;
    }
    .btn-colla{
        width: 40px;
        height: 30px;
        line-height: 30px;
        border: none;
        background-color: #F6F7F8;
    }
    .btn-colla .layui-icon{
        right: 7px;
    }
    .kqform-content {
        overflow: auto;
    }
    .kq-info-title {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        margin-right: 30px;
    }
    #usermemo{
        overflow: hidden;
    }
    #usermemo .layui-form-label{
        width: auto;
        padding:  9px 10px;
    }
    .layui-layer-btn .layui-layer-btn0{
        background-color: #2669B1;
        border-color: #2669B1;
    }
    .left-card .no-data-tips{
        margin-top: 70px;
    }
    .task-ul .no-data-tips{
        margin-top: 100px;
    }
    .layui-tab-content .layui-form-select{
        width: 200px;
        margin: auto;
    }
    .layui-tab-content .layui-table th{
        border: 1px solid #e6e6ee;
    }
    .height-auto{
        height: 385px;
    }
    .height-max{
        height: 825px;
    }
    .download-fileBox{
        position: relative;
    }
    .fileAllBox{
        position: absolute;
        left: 14%;
        top: 26px;
        background: #000;
        display: none;
        padding: 6px;
        z-index: 9999;
    }
    .fileAllBox p{
        color: white;
        font-size: 14px;
    }

    .dataFill-upload{  
        word-wrap: break-word;
        white-space: pre-wrap;
        word-break: break-all;
        max-width: 100%;
        height: auto;
        overflow: hidden;
        color: #23559D;
    }
    .upLoadSucessBox{
        position: absolute;
        left: 14%;
        top: 26px;
        background: #000;
        display: none; 
        z-index: 9999;
        color: #fff;
    } 
    .upLoadSucessBox>div{
        padding: 3px 6px;
    }
    .upLoadSucessBox>div>span:nth-child(1){
        cursor: pointer;
    }
    .upLoadSucessBox>div>span:nth-child(1):hover{
        color: #8ca8c7;
       
        text-decoration: underline;
    }
    .delDataFillBtn{
        display: inline-block;
        margin-left: 8px;
        cursor: pointer;
        color: #db3e0d;
    }
    .showEntuserCircle{
        display: inline-block;
        width: 10px;
        height: 10px;
        position: absolute;
        background: #ef5757;
        border-radius: 50%;
        top: 35%;
        right: 6px;
        cursor: pointer;
    }
</style>
<div class="custom-dataReview-page">
    <div class="layui-fluid top-part">
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md12">
                <div class="layui-card left-card">
                    <div class="layui-card-header">
                        <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                        <span class="card-header-title">待审核任务列表</span>
                    </div>
                    <div class="layui-card-body task-to-reviewBox">
                        <table class="layui-hide task-list" id="task-to-review" lay-filter="task-to-review"></table>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3 layui-hide">
                <div class="layui-card right-card">
                <div class="layui-card-header undo-task">
                    <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                </div>
                <div class="task-ul">
                    <ul class="scroll"></ul>
                </div>
                </div>
            </div>
      </div>
    </div>
    <div class="layui-fluid">
        <div class="layui-col-md12">
          <div class="layui-card select-form-box" style="margin: 0;">
              <div class="layui-card-header clearfix select-form-header">
                  <div class="card-header-left left">
                      <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                      <div class="layui-inline custom-card-header">
                        <span class="card-header-title">审核表单详情</span>
                        <span class="layui-title-mid layui-hide">-</span>
                        <span class="card-header-subtitle"></span>
                    </div>
                  </div>
                  <div class="card-header-right layui-btn-check right card-header-other hide">
                      <button class="layui-btn layui-btn-normal layui-btn-pass E-btn" data-target="pass">通过</button>
                      <button class="layui-btn layui-btn-normal layui-btn-back E-btn" data-target="back">退回</button>
                      <button class="layui-btn layui-btn-primary btn-colla E-btn" data-target="colla">
                          <i class="layui-icon layui-icon-up"></i>
                      </button>
                  </div>
                  <div class="card-header-right layui-btn-check right card-header-kq hide">
                      <div class="kq-info-title">
                          <span>填报单位：</span><span class="c-unit"></span>&nbsp;&nbsp;
                          <span>考勤日期：</span><span class="c-startDate"></span>~<span class="c-endDate"></span>
                      </div>
                      <button class="layui-btn layui-btn-normal layui-btn-pass E-btn" data-target="pass-kq">通过</button>
                      <button class="layui-btn layui-btn-normal layui-btn-back E-btn" data-target="back-kq">退回</button>
                      <button class="layui-btn layui-btn-primary btn-colla E-btn" data-target="colla">
                          <i class="layui-icon layui-icon-up"></i>
                      </button>
                  </div>
              </div>
              <div class="layui-tab layui-form layui-tab-card otherForm-content" lay-filter='tabSwitch'>
                  <ul class="layui-tab-title form-tab-title"></ul>
                  <div class="unit-radios" id="dept"></div>
                  <div class="layui-tab-content form-tab-content">
                    <div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>
                  </div>
              </div>
              <div id="audit-form-kqform" class="kqform kqform-content"></div>
            </div>
        </div>
    </div>
</div>

<!-- 任务状态模板 -->
<script type="text/html" id="taskState">
    {{#
		var getStatusColor = function() {
			var mapColors = {
                '00': 'layui-bk-green',
                '20': 'layui-bk-gray',
                '25': 'layui-bk-orange',
                '30': 'layui-bk-green',
                '40': 'layui-bk-orange',
                '90': 'layui-bk-gray',
                '99': 'layui-bk-gray'
			};
			return mapColors[d.state] || '';
        };
        var disPlayTxt=d.entuser_name?'inline-block':'none' 
	}}
    <!-- <span class="custom-badge {{getStatusColor()}}">{{d.statename}}</span>	 -->
    <div class="custom-badge {{getStatusColor()}}">{{d.statename}}<span  class="showEntuserCircle" style="display:{{disPlayTxt}}" lay-tips='委托人：{{d.entuser_name}}'></span></div>		
</script>
<!-- 日期时间 -->
<script type="text/html" id="datetime">
    <div class="dateTimeSpan"></div>
    <!-- <input type="text" name="approvalTime" class="layui-input layui-input-date"> -->
</script>
<!-- 上传附件 --> 
<script type="text/html" id="fileUploadTem"> 
    <div class="dataFillfileBox">
        <a href="javascript:void(0)" class="dataFill-upload">下载附件</a>
        <div class="upLoadSucessBox"></div>
    </div>
</script>
<!-- 工具栏模板 -->
<script type="text/html" id="examine">
    {{# if(!!d.fileNames && d.fileNames.length && d.fileNames.length > 0){     }}
        {{#   layui.each(d.fileNames, function(index, file){ }}
            <a class="download-file" lay-event="download" data-url={{file.url}} lay-tips='{{file.filename}}'>{{file.filename}}</a>
        {{# }); }}    
    {{# } }}
</script>

<!-- 待办任务 -->
<script type="text/html" id="auditTask">
    {{# if(d && d.length > 0){ }}
        <li class="undotask-header">
            <span class="title-num">序号</span>
            <span class="title-content">任务名称</span>
            <span class="title-time">填报结束时间</span>
        </li>
        {{# layui.each(d, function(index, item){ }}
            <li class="clearfix E-btn" data-jump={{item.connection}} data-target="jump">
                <div class="task-content-box">
                    <span class="task-num">{{index+1}}</span>
                    <span class="task-content"  lay-tips={{item.taskname}}>{{item.statename}}-{{item.taskname}}</span>
                </div>
                <div class="task-time">{{item.endtime}}</div>
            </li>
        {{# }); }}
    {{# }else{ }}
        <div class="no-data-tips">
            <img src="/src/style/res/about/empty.png">
            <p style="color:#DBDBDB;">暂无数据</p>
        </div>
    {{# } }}
</script>

<!-- 填报表单工具栏 -->
<script type="text/html" id="modify-form">
    {{# if(d.model != 'insert'){ }}
        <button class="checkLine" lay-event="check" lay-tips="查看记录"><i class="layui-icon layui-icon-form"></i></button>
    {{# } }}
</script>

 <!-- 单位单选框 -->
<script type="text/html" id="unitRadios">
    {{#  if(d && d.length > 0){ }}
        {{# layui.each(d, function(index, item){ }}
            <input type="radio" name="dept" value="{{item.dept_id}}" title="{{item.dept_name}}" lay-filter="custom-unit-radio" {{item.checked ? "checked" : ""}} />
        {{# }) }}
    {{#  } }}
</script>

<script>
layui.use(['admin', 'table', 'element', 'tools', 'laytpl', 'laydate', 'form', 'tablePlug'], function(){
    var layer = layui.layer,
        element = layui.element,
        table = layui.table,
        admin = layui.admin,
        tools = layui.tools,
        setter = layui.setter,
        view = layui.view,
        laytpl = layui.laytpl,
        laydate = layui.laydate,
        router = layui.router(),
        search = router.search,
        form = layui.form;

    var delRows = [], //删除行数据
        colName = [], //列名
        layout = ['.layui-table th', '.layui-table td', '.task-ul>ul'],
        FormData = [];
    window.tabIndex = 0; //选项卡下标 默认为0
    window.tableId = 'test-table-cellEdit1'; //选项卡表单id

    tools.initCite(router, {kqfirstMenu: '考勤管理', kqsecondMenu: '数据审核'}, {czfirstMenu: '审核管理', czsecondMenu: '数据审核'}); 
    initTask();
    addToolListen(); //监听工具栏

    //待审核任务列表
    function initTask(){
        table.render({
            elem: '#task-to-review'
            ,height: 385
            ,url: 'myapi/DC/api/rest/web/custom/Recheck'
            ,where: {
                model:'selectTask',
                jsonId: layui.data('layuiAdmin').access_token,
                access_token: layui.data('layuiAdmin').access_token
            }
            ,text: {
                none: '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
            }
            ,request: {
                limitName: 'count'
            }
            ,parseData: function(res){ 
                return {
                    "code": res.retcode, 
                    "msg": res.retmsg, 
                    "count": res.data.totalNumber, 
                    "data": res.data.data 
                };
            }
            ,cellMinWidth: 80 
            ,page: {
                groups: 1, 
                limit: 10,
                next:'<i class="layui-icon">&#xe602;</i>',
                prev:'<i class="layui-icon">&#xe603;</i>',
                first: '<i class="layui-icon">&#xe65a;</i>',
                last: '<i class="layui-icon">&#xe65b;</i>',
                layout: ['refresh', 'first', 'prev', 'skip', 'count', 'allPage', 'next', 'last'],
                extend:{
                    first: true, //是否显示首页
                    spr: false,//是否显示页码分页符号 默认显示
                    pagecount: true//页码是否显示总数  groups=1时才有效
                }
            }
            ,cols: [[
                    { type: 'numbers', title: '序号', width: 44 }
                    ,{title: '任务状态', toolbar: '#taskState', width: 105 }
                    ,{
                        field:'taskname', 
                        title: '任务名称', 
                        width: 300,
                        templet: function(d){
                            return '<span lay-tips="'+ d.taskname +'">'+ d.taskname +'</span>'
                        }
                    }
                    ,{field: 'username', title: '发布人', width: 150}
                    ,{field: 'deptname', title: '任务发布单位', width: 150}
                    ,{field: 'createtime', title: '创建时间', width: 200, 
                        templet: function(d){
                            return '<span lay-tips="'+ d.createtime +'">'+ d.createtime +'</span>'
                        }
                    }
                    ,{field:'endtime', title: '截止日期',  
                        templet: function(d){
                                return '<span lay-tips="'+ d.endtime +'">'+ d.endtime +'</span>'
                            }
                    }
                    ,{  
                        field:'memo', 
                        title: '填报要求',
                        templet: function(d){
                            return '<span lay-tips="'+ d.memo +'">'+ d.memo +'</span>'
                        }
                    } 
                    ,{title: '任务附件', 
                     //toolbar: '#examine'
                         width:200, 
                        field: 'fileNames',
                            templet: function(d){   
                                var newDownLoadBox="";
                                var fileNames=d.fileNames;
                                if(fileNames&&fileNames.length>0){
                                    for(var i=0;i<fileNames.length;i++){
                                        newDownLoadBox+='<p class="download-file" lay-event="download" data-taskid='+fileNames[i].taskid+' data-url='+fileNames[i].url+' >'+fileNames[i].filename+'</p>'
                                    }   
                                    return ' <div class="download-fileBox">'+
                                            '<a class="download-file downLoadFileBtn" taskid='+d.taskid+' >下载附件</a>'+  
                                            '<div class="fileAllBox">'+
                                                newDownLoadBox+
                                            '</div>'+
                                            '</div>'
                                    
                                }else{
                                    return '' 
                                }
                                // <a class="download-file" lay-event="download" data-url={{file.url}} lay-tips='{{file.filename}}'>{{file.filename}}</a>
                                }  
                            }
                    ,{ field: 'deptname', title: '下发单位' }
            ]]
            ,even: true 
            ,done: function(res, curr, count){
                $(".download-fileBox").parent(".layui-table-cell").css({"overflow":"visible"})
                $(".download-fileBox").mouseover(function(){  
                    $(this).find(".fileAllBox").show();  
                })
                $(".download-fileBox").mouseout(function(){ 
                    $(this).find(".fileAllBox").hide(); 
                })
                $(".downLoadFileBtn").click(function(){
                    tools.downLoadMutipleFileFun($(this).attr("taskid"))
                    
                })
                if(res.data && res.data.length > 0){
                    var isChecking = res.data[0].checking;
                    //clickForTr(res.data[0], isChecking);
                    window.taskId = res.data[0].id;
                    tools.clickToTask(res.data, router, 'task-to-review');
                     
                }else{
                    //清除考勤任务
                    $('#audit-form-task-kqform').empty();
                    $('.kq-info-title .c-unit').text('');
                    $('.kq-info-title .c-startDate').text('');
                    $('.kq-info-title .c-endDate').text('');
                    $('.card-header-kq').addClass('hide');
                    $('.kqform-content').hide();
                    //清理普通任务
                    $('.form-tab-title').empty();
                    $('#'+window.tableId).next().find('.layui-table-box').empty();
                }
                tools.setFont(layout);
                
            }
        });
    }

    //填报考勤任务表单详情列表加载
    function getKQTaskForm(taskid, callback) {
        admin.req({
            type: 'get',
            url: 'myapi/DC/api/rest/web/custom/GetFormsByWriteTask',
            data: {
                taskid: taskid,
                checking: '1',
            },
            success: function(res) {
                var dates = res.data.data.users.length > 0 ? res.data.data.users[0].users_time[0].users_time_day : [],
                    users = res.data.data.users;
                $('.kq-info-title .c-startDate').text(res.data.data.starttime ||' 暂无');
                $('.kq-info-title .c-endDate').text(res.data.data.endtime ||' 暂无');
                view('audit-form-kqform').render('./audit/components/kqReviewTable', {
                    dates: dates, 
                    users: users,
                    basic: {
                        dept_code: res.data.data.dept_code,
                        dept_name: res.data.data.dept_name,
                        dept_id: res.data.data.dept_id,
                        taskid: taskid
                    }
                });
                callback && callback(res);
                tools.setFont(layout);
            }
        });
    }
    //鼠标移入事件
    $("body").delegate(".dataFillfileBox","mouseover",function(){
        $(this).find(".upLoadSucessBox").show();  
    })
    $("body").delegate(".dataFillfileBox","mouseout",function(){
        $(this).find(".upLoadSucessBox").hide();  
    })  
    //下载文件删除文件点击操作 
    $("body").delegate(".DataFilldownLoadFile","click",function(e){//下载 
        e.stopPropagation();
        e.preventDefault();
        tools.downLoadfunction("myapi/DC/api/rest/web/custom/downWriteFile",{id:$(this).parent().attr("fileid"),access_token: layui.data('layuiAdmin').access_token},"download")
    })
    //下载多文件 
    $("body").delegate(".dataFill-upload","click",function(e){//下载 
        e.stopPropagation();
        e.preventDefault();
        var downloadp={
            dataid:$(this).siblings().attr("dataid"),
            fieldenglish:$(this).siblings().attr("fieldenglish"),
            access_token: layui.data('layuiAdmin').access_token
        }  
        tools.downLoadMutipleDataFun("myapi/DC/api/rest/web/custom/downWriteFile",downloadp);
    })
    //加载审核表单
    function getTaskForm(taskid,entuser_code, deptId, loadForm){
        var loadForm = loadForm ? loadForm : '',
            deptId = deptId ? deptId : '';
            
        admin.req({
            type: 'post',
            url: 'myapi/DC/api/rest/web/custom/Recheck',
            data: {
                taskid: taskid,
                entuser_code:entuser_code?entuser_code:"",
                model: 'selectFormData',
                jsonId: layui.data('layuiAdmin').access_token,
                dept_id: deptId
            },
            success: function(res) { 
                if(res.retcode == '0'){   
                    FormData = res.data || [];  
                    setUnitRadios(FormData[window.tabIndex]?FormData[window.tabIndex]:{}, deptId);
                    loadForm && loadForm(res);
                    $('#'+window.tableId).empty();
                    var titleHtml = '',
                        tableHtml = '';
                    for(var i = 0; i < FormData.length; i++){
                        if(i == window.tabIndex){ 
                            titleHtml +=  '<li class="layui-this" tableId="test-table-cellEdit'+(i+1)+'">'+FormData[i].formname+'</li>';
                            tableHtml += '<div class="layui-tab-item layui-show" id='+FormData[i].id+'>'+
                                            '<table id="test-table-cellEdit'+(i+1)+'" lay-filter="test-table-cellEdit'+(i+1)+'"></table>'+
                                         '</div>';
                        }
                        else{ 
                            titleHtml += ' <li tableId="test-table-cellEdit'+(i+1)+'">'+FormData[i].formname+'</li>';
                            tableHtml += '<div class="layui-tab-item" id='+FormData[i].id+'>'+
                                            '<table id="test-table-cellEdit'+(i+1)+'" lay-filter="test-table-cellEdit'+(i+1)+'"></table>'+
                                         '</div>';
                        }
                    }
                    $('.form-tab-title').empty().html(titleHtml);
                    $('.form-tab-content').empty().html(tableHtml);
                    layui.each(FormData, function(index, item){
                        var field = item.form_field,
                            cols = item.cols,
                            tbody = item.data.grid,
                            warnResults = item.dv_results,
                            colsss = [],
                            colData = [],
                            fieldRole = item.fieldRole,
                            finalCols = [],
                            supContent = item.supcontent;
                            obj = new Object(),
                            selfId = item.id,
                            maxRow  = 1,
                            dataFillfiles=item.files;	 
                        //得到数据标题行
                        $.each(field,function(index, item) {
                            $.each(fieldRole, function(i, role){
                                if(item.fieldenglish == role.fieldenglish){
                                    item.see = role.see;
                                    item.edit = role.edit;
                                }
                            });
                            colName.push(item.fieldenglish);
                            // if(item.datatype != 'date'){
                                var see = item.see, edit = item.edit; 
                                if(item.datatype== 'upload'){//加载上传附件的框
                                        if(item.see != '0'){ 
                                            finalCols.push({
                                                field: item.fieldenglish, 
                                                title: item.fieldname,
                                                minWidth: 230,
                                                event: [item.nonull, item.datatype],
                                                templet: '#fileUploadTem'
                                            })
                                        } 
                                    }else{
                                        if(see != '0'){ 
                                            var param = {
                                                field: item.fieldenglish,
                                                title: item.fieldname,
                                                minWidth: 250,
                                            };
                                            param.event = edit && edit == '0' ? 'mustFill' : [item.nonull, item.datatype];
                                            finalCols.push(param);
                                        }
                                    } 
                            // }else{
                            //     if(item.see != '0'){ 
                            //         finalCols.push({
                            //             field: item.fieldenglish,
                            //             title: item.fieldname,
                            //             minWidth: 230,
                            //             event: [item.nonull, item.datatype],
                            //             templet: '#datetime'
                            //         });
                            //     }
                            // }
                        });
                        
                        colsss = tools.handleCols(cols, finalCols);		
                        tools.addOtherCols(colsss);
        													
                        if(tbody.length > 0){ 
                            colData = tbody;
                            layui.each(colData, function(index, item){
                                item.model = 'normal';
                                item.tableId = selfId;
                            })
                        }else{ //无内容默认加载maxRow个空行
                            for(var i = 0; i < maxRow; i++){
                                var blankLine = {};
                                for(var j = 0; j < colName.length; j++){
                                    blankLine[colName[j]] = "";
                                    blankLine.model = "insert";
                                    blankLine.id = createUniqueId(1);
                                    blankLine.tableId = selfId;
                                }
                                colData.push(blankLine);
                            }
                        }
                        tools.handleWarnInfo(colsss, warnResults);
                        var options = {
                            elem: '#test-table-cellEdit'+(index+1)
                            ,cols: colsss
                            ,skin: 'nob'
                            ,height: 270
                            ,even: true
                            ,limit: 5000
                            ,data: colData
                            ,done: function(res, curr, index){
                                var data = res.data;
                                supContent = tools.handleSelectVal(supContent, tbody, data[0].tableId);
                                tools.loadSelectFunction(supContent);
                                //加载下拉选值框
                                var tableId = data[0].tableId,
                                    selectDiv = $('#'+tableId+' td[lay-event]');
                                $.each(selectDiv, function(k, each){
                                    var tr = $(this).parents('tr').index(),
                                        event = $(this).attr('lay-event').split(',')[1];
                                    if(event && event == 'select'){
                                        var field = $(this).data('field'),
                                            selectVal = data[tr][field] || '';
                                        $(this).find('select').val(selectVal)
                                    }
                                });  
                                //加载下拉文件
                                if(JSON.stringify(dataFillfiles)!='{}'){  
                                    //循环文件对象
                                    var newFileDataArr=[]; 
                                    for(var fileKey in dataFillfiles){
                                        var newObj={};
                                        newObj.trId=fileKey.split("@")[0];
                                        newObj.tdFilesh=fileKey.split("@")[1];
                                        newObj.fileData=dataFillfiles[fileKey];
                                        newFileDataArr.push(newObj);
                                    } 
                                    for(var i=0;i<data.length;i++){
                                        for(var j=0;j<newFileDataArr.length;j++){
                                            if(newFileDataArr[j].trId==data[i].dataid){ 
                                                var eachFileData=newFileDataArr[j].fileData;
                                                for(var k=0;k<eachFileData.length;k++) {
                                                    var newEachFileItem='<div fileId='+eachFileData[k].id+' dataid='+eachFileData[k].dataid+'  fieldenglish='+eachFileData[k].fieldenglish+' servername='+eachFileData[k].servername+' ><span  class="DataFilldownLoadFile">'+eachFileData[k].filename+'</span></div>';
                                                    $(".dataFillfileBox").eq(i).find(".upLoadSucessBox").append(newEachFileItem);
                                                    $(".dataFillfileBox").parent(".layui-table-cell").css({"overflow":"visible"}); 
                                                } 
                                                if(eachFileData.length>0){
                                                    $(".dataFillfileBox").eq(i).find(".upLoadSucessBox").attr('dataid',eachFileData[0].dataid);
                                                    $(".dataFillfileBox").eq(i).find(".upLoadSucessBox").attr('fieldenglish',eachFileData[0].fieldenglish);
                                                } 
                                            }  
                                        }
                                    }
                                } 
                                //下载附件判断没有子节点就隐藏
                                $.each($(".dataFillfileBox"),function(index,item){ 
                                    var dataidFlag=$(item).find(".upLoadSucessBox").attr('dataid');
                                    if(!dataidFlag){
                                        $(item).css("display","none");
                                    }
                                })
                                //加载日期选择框
                                $('.dateTimeSpan').each(function(index, item){
                                    var field = $(this).parents('td').data('field'),
                                        datatime = ''; 
                                    if(data[index][field]){
                                        datatime = $.trim(data[index][field]);
                                    } 
                                    $(this).html(datatime);
                                    // laydate.render({
                                    //     elem: this,
                                    //     type: 'date',
                                    //     format: 'yyyy-MM-dd',
                                    //     isInitValue: true, 
                                    //     value: datatime, 
                                    //     trigger: 'click'
                                    // })
                                });
                                form.render('select', 'tabSwitch');
                                tools.setFont(layout);
                            }
                        }
                        table.render(options);
                    })
                }else{
                    $('.form-tab-title').empty();
                    $('#'+window.tableId).next().find('.layui-table-box').empty();
                }
            }
        })
    }

    //待办任务
    function getUndoTask(){
        var appid = layui.data('userdata').appId;
        admin.req({
            url: 'myapi/DC/api/rest/web/custom/GetTasksByUserApp',
            data: {
                app_id: appid,
            },
            success: function(res){
                if(res.retcode == '0'){
                    var data = res.data.auditTask.concat(res.data.writeTask),
                        getTpl = auditTask.innerHTML,
                        view = document.querySelector('.task-ul ul');
                    laytpl(getTpl).render(data, function(html){
                        view.innerHTML = html;
                    })
                }
            }
        })
    }

    //设置填报表单单位单选框
    function setUnitRadios(data, checkId){   
        var deptMsgs = data.deptMsgs || [],
            view = document.getElementById('dept'),
            getTpl = unitRadios.innerHTML;
        if(deptMsgs && deptMsgs.length > 0){
            deptMsgs && deptMsgs[0].dept_name != '全部' ? deptMsgs.unshift({dept_name: '全部', dept_id: ''}) : '';
            layui.each(deptMsgs, function(index, item){
                item.checked = false;
                item.dept_id == checkId ? item.checked = true : ''
            });
        }
        laytpl(getTpl).render(deptMsgs, function(html){
            view.innerHTML = html;
        });
        form.render('radio', 'tabSwitch');
    }

    //生成唯一id
    function createUniqueId(n) {
		var random = function() { // 生成10-12位不等的字符串
		    return Number(Math.random().toString().substr(2)).toString(36); // 转换成十六进制
		}
		var arr = [];
		function createId() {
		    var num = random();
		    var bool = false;
            for(var i = 0; i < arr.length; i++){
                if(arr[i] === num){
                    bool = true
                }
            }
		    if(bool) {
		        createId();
		    }else {
		        arr.push(num);
		    }
		}
		var i = 0;
		while(i < n) {
		    createId();
		    i++;
		}
		return arr[0];
	}

    //不同任务类型做不同的元素切换
    function pickTypeShow(type) {
        if(type === 'other') {
            $('.otherForm-content').show();
            $('.kqform-content').hide();
            $('.card-header-other').show();
            $('.card-header-kq').hide();
        }else if(type === 'kqform') {
            $('.otherForm-content').hide();
            $('.kqform-content').show();
            $('.card-header-other').hide();
            $('.card-header-kq').show();
        }
    }

    //监听Tab切换
    element.on('tab(tabSwitch)', function(data){
        var index = data.index + 1;
        window.tableId = 'test-table-cellEdit'+index; //表格ID
        window.tabIndex = data.index; //选项卡下表
        addToolListen(); //监听工具栏
        setUnitRadios(FormData[tabIndex], '');
    });

    //监听单位单选框单选
    form.on('radio(custom-unit-radio)', function(data){
        getTaskForm(window.taskId,'',data.value);
    });

    //任务列表 => 监听行点击事件
    table.on('row(task-to-review)', function(obj){
        $('[lay-id="task-to-review"]').find(obj.tr.selector).addClass('lineactive');
        $('[lay-id="task-to-review"]').find(obj.tr.selector).siblings().removeClass('lineactive');
        window.tabIndex = 0;
        window.tableId = 'test-table-cellEdit1'; 
        tools.setNavText();
        tools.setTaskFormTitle(obj.data.taskname);
        clickForTr(obj.data, obj.data.checking);
        window.taskId = obj.data.id;
    });

    //行点击事件
    function clickForTr(data,checking) {
        if(checking === '1') {
            getKQTaskForm(data.id);
            $('.kq-info-title .c-unit').text(data.deptname ||' 暂无');
            pickTypeShow('kqform');
        }else { 
            getTaskForm(data.id,data.entuser_code);
            pickTypeShow('other');
        }
    }

    //按钮点击事件
    $('.E-btn').click(function(){
        var target = $(this).data('target');
        if(target == 'pass' || target == 'back'){ //常驻任务通过退回
            var activeTabId = $('.form-tab-title li.layui-this').attr('tableid'),
                checkData = table.checkStatus(activeTabId).data,
                selectIds = [],
                taskmodel = target == 'pass' ? 'pass' : 'back';
                memoTitle = target == 'pass' ? '通过意见' : '退回意见';
            if(checkData && checkData.length > 0){
                layui.each(checkData, function(kndex, ktem){
                    ktem.id && selectIds.push(ktem.id);
                });
                if(selectIds && selectIds.length <= 0){
                    layer.msg('空行数据无法通过或退回', {time: 1000});
                    return ;
                }
                layer.open({
                    id: 'usermemo',
                    type: 1,
                    title: '<i class="formFill-icon"></i><span style="color:#FFF;">'+memoTitle+'</span>',
                    area: ['300px', '250px'],
                    offset: 'auto',
                    shadeClose: true,
                    resize: false,
                    success: function(lay, index){
                        view(this.id).render('./audit/components/usermemo', {
                            showReview: false
                        });
                    },
                    btn: ['确定', '取消'],
                    btnAlign: 'c',
                    yes: function(index, layero){
                        var memoval = $('#usermemo .layui-textarea').val();
                        admin.req({
                            url: 'myapi/DC/api/rest/web/custom/Recheck',
                            type: 'post',
                            data: {
                                model: taskmodel,
                                usermemo: memoval,
                                taskid: window.taskId,
                                dataIds: JSON.stringify(selectIds)
                            },
                            success: function(res){
                                if(res.data.retcode == '0'){
                                    window.tabIndex = 0;
                                    target == 'pass' ? layer.msg('通过成功', {time: 1000}) : layer.msg('退回成功', {time: 1000});
                                    getTaskForm(window.taskId, '','', loadForm = function(res){ 
                                        if(res.retcode == '0' && !res.data){
                                            initTask();
                                            $('#dept').empty();
                                        }
                                    });
                                }else{
                                    layer.msg(res.data.retmsg, {time: 1000});
                                }
                                layer.close(index);
                            }
                        })
                    }
                });
            }else{
                layer.msg('请勾选需要审核的数据', {time: 1500});
            }
        }else if(target == 'pass-kq' || target == 'back-kq'){ //考勤任务通过退回
            var writeuserids = [];
            $('#audit-form-kqform').find('tbody .T-firstTr').each(function(index, el) {
                if(!$(el).find('.T-isChecked').is(':checked')) {
                    return true;
                }
                var wrid = $(el).data('id').replace(',','');
                writeuserids.push(wrid);
            });
            if(writeuserids.length > 0){
                var model = '',
                    memoTitle = '';
                if(target === 'pass-kq') {
                    model = 'pass';
                    memoTitle = '通过意见';
                }else if(target === 'back-kq') {
                    model = 'back';
                    memoTitle = '退回意见';
                }
                layer.open({
                    id: 'usermemo',
                    type: 1,
                    title: '<i class="formFill-icon"></i><span style="color:#FFF;">'+memoTitle+'</span>',
                    area: ['300px', '250px'],
                    offset: 'auto',
                    shadeClose: true,
                    resize: false,
                    success: function(lay, index){
                        view(this.id).render('./audit/components/usermemo', {
                            title: '意见'
                        });
                    },
                    btn: ['确定', '取消'],
                    btnAlign: 'c',
                    yes: function(index, layero){
                        var memoval = $('#usermemo .layui-textarea').val();
                        admin.req({
                            url: 'myapi/DC/api/rest/web/custom/CheckTaskDataPassAndBack',
                            type: 'post',
                            data: {
                                checking: '1',
                                model: model,
                                usermemo: memoval,
                                writeuserids: JSON.stringify(writeuserids),
                                taskid: window.taskId,
                                access_token: layui.data(setter.tableName)[setter.request.tokenName]
                            },
                            success: function(res){
                                if(res.retcode == '0'){
                                    window.tabIndex = 0;
                                    target == 'pass-kq' ? layer.msg('提交成功') : layer.msg('退回成功');
                                    layer.close(index);
                                    getKQTaskForm(window.taskId, success = function(res){
                                        var data =  res.data.data;
                                        res.data.retcode == 0 && data.users && data.users.length == 0 && initTask();
                                    });
                                    //getUndoTask();
                                }
                            }
                        })
                    },
                    btn2: function(index, layero){}
                })
            }else{
                layer.msg('请勾选需要审核的数据', {time: 1500})
            }
        }else if(target == 'colla'){
            var tbHeight = 0,
                flag = $(this).find('.layui-icon').hasClass('layui-icon-up');
            $('.left-card').slideToggle();
            $('.right-card').slideToggle();
            $(this).find('i').toggleClass("layui-icon-up layui-icon-down");
            $(this).parents('.select-form-box').toggleClass('height-auto height-max');
            tbHeight = flag ? 700 : 250;
            table.reload(window.tableId, {
                height: tbHeight
            });
        }
    })

    //待办任务点击事件
    $('.task-ul').delegate('li.E-btn', 'click', function(){
        var toJump = $(this).attr('data-jump');
        location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/'+toJump;
    })
      
    //下载附件
    table.on('tool(task-to-review)', function(obj){
        var event = obj.event;
        if(event == 'download'){
            var url = 'myapi/DC/'+ $(this).data('url'),
                name = $(this).text(),
                taskid=$(this).data('taskid');
                tools.downMethodfunction(url, name,taskid); 
        }
    })

    //表单详情表格 => 监听表格新增行删除行 
    function addToolListen(){
        table.on('tool('+window.tableId+')', function(obj){
            var event = obj.event;
            if(event == 'addLine'){
                var Data = table.cache[""+window.tableId+""]; //当前表格所有数据
                var randomId = createUniqueId(1);
                var datas = {
                    model: "insert",
                    id: randomId
                }
                for(var i = 0; i < colName.length; i++){
                    datas[colName[i]] = "";
                }
                Data.push(datas);
                table.reload(window.tableId, {  
                    data: Data
                })
            }else if(event == 'delLine'){
                var Data = table.cache[""+window.tableId+""];
                var index = obj.tr.data('index');
                var randomId = createUniqueId(1);
                layer.confirm('真的删除当前行么？', function(index2){
                    if(obj.data.model == 'normal'){
                        deleteRow(obj.data); 
                    }
                    Data.splice(index, 1);
                    obj.data.model = 'del';
                    delRows.push(obj.data);
                    if(index == 0){
                        var datas = {
                            model: "insert",
                            id: randomId
                        }
                        for(var i = 0; i < colName.length; i++){
                            datas[colName[i]] = "";
                        }
                        Data.push(datas);
                    } 
                    table.reload(window.tableId, {
                        data: Data
                    })
                    layer.close(index2);
                })
            }else if(event == 'check'){
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/GainHistory',
                    data: {
                        id: obj.data.dataid
                    },
                    done: function(res){
                        if(res.retcode == '0'){
                            if(res.data && res.data.length > 0){
                                var taskrecode = layer.open({
                                    id: 'temporary-addhtml',
                                    title:'<i class="formFill-icon"></i><span style="color:#FFF;">查看记录</span>',
                                    offset: '110px',
                                    type: 1,
                                    shadeClose: true,
                                    area: ['800px', '420px'],
                                    resize: false,
                                    success: function(lay, index){
                                        view(this.id).render('./task/temporary/history', {history: res.data});
                                    }
                                })
                            }else{
                                layer.msg('此任务暂没有记录');
                            }
                        }
                    }
                })
            }
        }) 
    }
})


</script>